package unit6.part10.test1;

import java.util.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<String> listOne = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            listOne.add(scanner.next());
        }
        n = scanner.nextInt();
        List<String> listTwo = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            listTwo.add(scanner.next());
        }
        List<String> list = new ArrayList<>();
        list.addAll(listOne);
        list.addAll(listTwo);

        Comparator<String> comparable = (a, b) -> Integer.parseInt(b) - Integer.parseInt(a);
        list.sort(comparable);

        List<String> l = list.subList(0, 3);
        System.out.println(String.join(" ", l));

        int countOne = 0;
        for (String str : l) {
            if (listOne.contains(str)) {
                countOne++;
            }
        }
        System.out.println(countOne >= 2 ? "A" : "B");
    }
}
